# header准备

city = [{'code': '410', 'name': '全国'},
 {'code': '010', 'name': '北京'},
 {'code': '020', 'name': '上海'},
 {'code': '030', 'name': '天津'},
 {'code': '040', 'name': '重庆'},
 {'code': '050020', 'name': '广州'},
 {'code': '050090', 'name': '深圳'},
 {'code': '060080', 'name': '苏州'},
 {'code': '060020', 'name': '南京'},
 {'code': '070020', 'name': '杭州'},
 {'code': '210040', 'name': '大连'},
 {'code': '280020', 'name': '成都'},
 {'code': '170020', 'name': '武汉'},
 {'code': '270020', 'name': '西安'}]

workExperiences = [{'code': '1', 'name': '应届生'},
 {'code': '2', 'name': '实习生'},
 {'code': '0$1', 'name': '1年以内'},
 {'code': '1$3', 'name': '1-3年'},
 {'code': '3$5', 'name': '3-5年'},
 {'code': '5$10', 'name': '5-10年'},
 {'code': '10$999', 'name': '10年以上'}]

# header准备
def headers():
    liepin_headers = {
         "Accept": "application/json, text/plain, */*",
         "Accept-Encoding": "gzip, deflate, br",
         "Accept-Language": "zh-CN,zh;q=0.9",
         "Connection": "keep-alive",
         "Content-Length": "487",
         "Content-Type": "application/json;charset=UTF-8;",
         "Cookie": "__uuid=1681904456296.00; __gc_id=a9bc2fb7f2064d5f8d78604b49445b4b; need_bind_tel=false; c_flag=2e06fa9ea225580f6a16e3dd21930b50; _ga=GA1.1.260202813.1681904546; imClientId=77cca5dbe480f7bf45d05ea1f04b5227; imId=77cca5dbe480f7bf96b8e949588eca97; imClientId_0=77cca5dbe480f7bf45d05ea1f04b5227; imId_0=77cca5dbe480f7bf96b8e949588eca97; new_user=false; XSRF-TOKEN=ouCmIbKlQi6O1kS351K3WQ; __tlog=1697021971239.21%7C00000000%7C00000000%7C00000000%7C00000000; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1697021972; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1697023061; __tlg_event_seq=61; _ga_54YTJKWN86=GS1.1.1697032920.11.1.1697032921.0.0.0; __session_seq=7; __uv_seq=7",
         "Host": "api-c.liepin.com",
         "Origin": "https://www.liepin.com",
         "Referer": "https://www.liepin.com/",
         "Sec-Fetch-Dest": "empty",
         "Sec-Fetch-Mode": "cors",
         "Sec-Fetch-Site": "same-site",
         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.202.400 QQBrowser/11.9.5355.400",
         "X-Client-Type": "web",
         "X-Fscp-Bi-Stat": "{\"location\": \"https://www.liepin.com/zhaopin/?currentPage=0&pageSize=40&city=050090&dq=050090&pubTime=&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&suggestTag=&otherCity=&industry=&ckId=geq5b0qsi9umzbhn0oojbi2j8v8qu2bb&scene=condition&skId=geq5b0qsi9umzbhn0oojbi2j8v8qu2bb&fkId=geq5b0qsi9umzbhn0oojbi2j8v8qu2bb&sfrom=search_job_pc&suggestId=\"}",
         "X-Fscp-Fe-Version": "",
         "X-Fscp-Std-Info": "{\"client_id\": \"40108\"}",
         "X-Fscp-Trace-Id": "c7fd8769-4982-4b4d-b342-39e01cc8fcb8",
         "X-Fscp-Version": "1.1",
         "X-Requested-With": "XMLHttpRequest",
         "X-XSRF-TOKEN": "ouCmIbKlQi6O1kS351K3WQ"
        }
    return liepin_headers  


# 准备城市code
def choose_city(city_name):
    for i in city:
        if i['name'] == city_name:
            return i['code']

# 准备工作经验code
def choose_WE(工作经验):
    for i in workExperiences:
        if i['name'] == 工作经验:
            return i['code']
# 准备payload
def request_payload(城市,关键词,工作经验):
    payload = {
        "data": {
            "mainSearchPcConditionForm": {
                "city": choose_city(城市),
                "dq": choose_city(城市),
                "pubTime": "",
                "currentPage": "0",
                "pageSize": 40,
                "key": 关键词,
                "suggestTag": "",
                "workYearCode": choose_WE(工作经验),
                "compId": "",
                "compName": "",
                "compTag": "",
                "industry": "",
                "salary": "",
                "jobKind": "",
                "compScale": "",
                "compKind": "",
                "compStage": "",
                "eduLevel": ""
            },
            "passThroughForm": {
                "scene": "condition",
                "skId": "0v9fe9gj95qvwr4jr8ciom91n3jhnsra",
                "fkId": "0v9fe9gj95qvwr4jr8ciom91n3jhnsra",
                "ckId": "5tky6f2yd0kmxyakii1lhwyv1lqukrcb",
                "suggest": None
            }
        }
    }
    return payload
    

